import router from '@/router'
import api from '../index'

export default {
  // 登录
  // api/modules/user.ts
  login: (data: {
    account: string
    password: string
  }) =>
    api.post('/api/user/login', data)
      .then((res) => {
        if (res.code === 200) {
          router.push('/')
          return res
        }
        else {
          return Promise.reject(new Error(res.msg || '登录失败'))
        }
      })
      .catch((error) => {
        console.error('接口请求失败:', error)
        return Promise.reject(new Error(error.message || '网络异常'))
      }),

  // 获取权限
  permission: () => api.get('user/permission', {
    baseURL: '/mock/',
  }),

  // 修改密码
  passwordEdit: (data: {
    password: string
    newPassword: string
  }) => api.post('user/password/edit', data, {
    baseURL: '/mock/',
  }),
}
